/** 节流 */
export const throttling = (fn: Function,delay: number,immediate = false) => {
    let timer:any = null;
    return (n: any)=>{
        if(!timer){
            immediate && fn(n);
            timer = setTimeout(()=>{
                !immediate && fn(n);
                clearTimeout(timer);
                timer = null;
            }, delay);
        }
    };
};

/** 防抖 */
export const debounce = (fn: Function, delay: any, immediate=false) => {
    let timer: any = null;
    return (n: any)=>{
        immediate && !timer && fn(n);
        timer && clearInterval(timer);
        timer = setTimeout(()=>{
            !immediate && fn(n);
            clearTimeout(timer);
            timer = null;
        },delay);
    };
};